#! /usr/bin/env python
# -*- coding: utf-8 -*

import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import Joy

class teleopJoy():
    def __init__(self):
        """初始化所有参数"""
        self.pub = rospy.Publisher('/turtle1/cmd_vel',Twist,queue_size=1)
        self.sub = rospy.Subscriber('joy', Joy, self.callback)
        self.axis_linear = rospy.get_param('axis_linear',1)
        self.axis_angular = rospy.get_param('axis_angular',0)
        self.vlinear = rospy.get_param('vel_linear',3)
        self.vangular = rospy.get_param('vel_angular',3) 

    def callback(self, joy):
        v = Twist()
        v.linear.x = joy.axes[self.axis_linear]*self.vlinear
        v.angular.z = joy.axes[self.axis_angular]*self.vangular
        self.pub.publish(v)

if __name__ == '__main__':
    rospy.init_node('tellopjoy', anonymous=True)
    teleopJoy()
    rospy.spin()